package arithmetic1.demo;

import java.util.Scanner;

public class QuickSort {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String string = scanner.nextLine();
		String[] strings = string.split(" ");
		int n = Integer.parseInt(strings[0]);
		int k = Integer.parseInt(strings[1]);
		int arr[] = new int[n];
		String line = scanner.nextLine();
		strings = line.split(" ");
		for(int i=0;i<n;i++) {
			arr[i] = Integer.parseInt(strings[i]);
		}
		System.out.println(quickSort(arr,0,arr.length-1,k));
		scanner.close();
	}

	//����
	public static int partition(int[] arr,int start,int end) {
		int i = start;
		int j = end;
		int temp = arr[start];
		while(i!=j) {
			while(j>i && arr[j]>=temp) {
				j--;
			}
			arr[i] = arr[j];
			while(i<j && arr[i]<=temp) {
				i++;
			}
			arr[j] = arr[i];
		}
		arr[i] = temp;
		return i;
	}

	//��������
	public static int quickSort(int[] arr,int start, int end,int k) {
		if(start<end) {
			//����
			int i = partition(arr, start, end);
			//����������еĸ���
			int num1 = i-1-start+1;
			int num2 = end-i-1+1;
			if(num1>=k) {	//��k������ǰ������
				//�ݹ�ǰ������
				return quickSort(arr,start,i-1,k);
			}else if(num1+1==k){	//�պ����м����
				return arr[num1+1];
			}else {	//�ں�������
				return quickSort(arr,i+1,end,k);
			}
		}
		return arr[k-1];
	}

}
